<?php

namespace app\merchants\controller;

use app\merchants\loader\Services;
use think\Exception;

/**
 * 轮播图
 */
class PointBanner extends ApiBase
{
    /**
     * 列表
     */
    public function page()
    {
        try {
            $where[] = ['mer_id', '=', $this->merId];
            $res = Services::Point()->banner_list($where);
            api_result($res);
        } catch (Exception $e) {
            api_result($e);
        }
    }
    /**
     * 详情
     */
    public function info()
    {
        $data = input('get.');
        try {
            $where[] = ['mer_id', '=', $this->merId];
            $where[] = ['id', '=', $data['id']];
            $res = Services::Point()->banner_info($where);
            api_result($res);
        } catch (Exception $e) {
            api_result($e);
        }
    }
    /**
     * 删除
     */
    public function del()
    {
        $data = input('post.');
        try {
            if (empty($data['id'])){
                throw new Exception('信息未找到',API_ERROR);
            }
            $where[] = ['mer_id', '=', $this->merId];
            $where[] = ['id', '=', $data['id']];
            Services::Point()->banner_del($where);
            api_result(API_SUCCESS,'删除成功');
        } catch (Exception $e) {
            api_result($e);
        }
    }
    /**
     * 保存
     */
    public function save()
    {
        $data = input('post.');
        try {
            $data['mer_id'] = $this->merId;
            Services::Point()->banner_save($data);
            api_result(API_SUCCESS,'保存成功');
        } catch (Exception $e) {
            api_result($e);
        }
    }

    /**
     * 保存字段信息
     */
    public function save_filed()
    {
        $data = input('post.');
        try {
            if (empty($data['id'])){
                throw new Exception('信息未找到',API_ERROR);
            }
            $data['mer_id'] = $this->merId;
            Services::Point()->banner_save($data);
            api_result(API_SUCCESS,'保存成功');
        } catch (Exception $e) {
            api_result($e);
        }
    }
}
